package security.Example;

import java.net.InetAddress;
import java.net.UnknownHostException;

import security.Authentication.Encrypted.EncryptedHandler;
import security.Authentication.Encrypted.EncryptedRequest;
import security.Authorization.UserRole.UserRole;
import security.LoginSystem.Base.LoginSystem;

/**
 * Example application of the authorization and authentication QAS
 */
public class ExampleAuthenticationAuthorization {

	/**
	 * Run the example application
	 * @param args no arguments is needed
	 * @throws UnknownHostException if the local host was not found
	 */
	public static void main(String[] args) throws UnknownHostException {
		// Create the login system that is the LoginSystem class
		LoginSystem loginSystem = new LoginSystem();
		
		// Create UserRole that is an implementation of the
		// AuthorizationHandler for the authorization.
		UserRole userRole = new UserRole();
		
		// Create a EncryptedHandler that is an implementation of the
		// abstract class AuthenticationHandler for the authentication.
		EncryptedHandler encryptedHandler = new EncryptedHandler();
		
		// Create a EncryptedRequest that is an implementation of the
		// abstract class AuthenticationRequest for the login request.
		InetAddress localHost = InetAddress.getLocalHost();
		EncryptedRequest request =
				new EncryptedRequest(localHost, "QwertyUser", "Qwerty1.");
		
		// Add the authentication and authorization to the system
		loginSystem.setAuthorization(userRole);
		loginSystem.addAuthentication(encryptedHandler);

		// Test that the correct authorization is made
		loginSystem.login(request);
	}
}
